#!/bin/bash

# Description: 自动测试
# File: tester.sh |Time: 2022-05-12 09:56

hash inotifywait
if [ $? -ne 0 ]; then
    echo "inotify-tools not exist, install inotify-tool"
    sudo apt install inotify-tools
fi

file_path=$1

if [[ -z $file_path  ]]; then
    echo "Usage: ./tester.sh /path/to/xxx.cpp"
    exit 0;
fi

if [[ ! (-f $file_path) ]]; then
    echo "file $file_path not exist"
    exit -1
fi

 while inotifywait -q -e  modify $file_path; do
    echo ""
    g++ $file_path -o test.out
    ./test.out
done

